//
//  FinancialViewController.m
//  BTCoin
//
//  Created by Robin on 26/03/2018.
//  Copyright © 2018 Robin. All rights reserved.
//

#import "FinancialViewController.h"
#import "UIView+Touch.h"
#import "GFNavigationController.h"
#import "LoginViewController.h"
#import "RechargeBtcViewController.h"
#import "FinancialPersonalVC.h"
#import "AssetsRecordViewController.h"
#import "AccountRecordViewController.h"
#import "VideoHomeCell.h"
#import "FinancialItemModel.h"

@interface FinancialViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@property (nonatomic, strong) NSArray * aryVideo;
@end

@implementation FinancialViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initData];
    [self initUIHead];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)initData {
    NSMutableArray * array = [[NSMutableArray alloc] init];
    NSArray * images = @[@"account_address_manager",@"account_id_verification",@"account_order_manager",@"account_security_center",@"account_setting",@"account_user_center"];
    NSArray * titles = @[@"充值",@"提现",@"个人资产",@"账单明细",@"资金账号",@"资产记录"];
    for (int i = 0; i < 6; i++) {
        FinancialItemModel * model = [[FinancialItemModel alloc] init];
        model.imageName = images[i];
        model.title = titles[i];
        [array addObject:model];
    }
    
    self.aryVideo = array;
}

- (void)initUIHead {
    [self.view addSubview:self.collectionView];
    [self.collectionView reloadData];
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _aryVideo.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    VideoHomeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"VideoHomeCell" forIndexPath:indexPath];
    
    FinancialItemModel * item = _aryVideo[indexPath.row];
    
    [cell setItemDataModel:item indexPath:indexPath];
    
    
    return cell;
}

#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
//    UserInfo * userInfo = [UserInfo sharedUserInfo];
//    if (!userInfo.bIsLogin) {
//        @WeakObj(self)
//        //未登录
//        LoginViewController *loginVC = [[LoginViewController alloc] init];
//        loginVC.boolBlock = ^(BOOL boolValue) {
//            [selfWeak itemSelected:indexPath.row];
//        };
//        [self presentViewController:loginVC animated:YES completion:nil];
//    } else {
//        [self itemSelected:indexPath.row];
//    }
    
    [self itemSelected:indexPath.row];
}

#pragma mark - private methods
- (void)itemSelected:(NSInteger)tag {
    switch (tag) {
        case 0: {
            RechargeBtcViewController * viewController = [RechargeBtcViewController new];
            [self.navigationController pushViewController:viewController animated:YES];
        }
            break;
        case 1: {
            
        }
            
            break;
        case 2: {
            FinancialPersonalVC * viewController = [[FinancialPersonalVC alloc] initWithNibName:nil bundle:nil];
            [self.navigationController pushViewController:viewController animated:YES];
        }
            
            break;
        case 3: {
            AccountRecordViewController * viewController = [[AccountRecordViewController alloc] initWithNibName:nil bundle:nil];
            [self.navigationController pushViewController:viewController animated:YES];
        }
            
            break;
        case 4:
            
            break;
        case 5: {
            AssetsRecordViewController * viewController = [AssetsRecordViewController new];
            [self.navigationController pushViewController:viewController animated:YES];
        }
            
            break;
            
        default:
            break;
    }
}

#pragma mark - getter & setter
- (UICollectionView *)collectionView {
    if (!_collectionView) {
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.headView.frame), kScreenWidth, kScreenHeight-(CGRectGetMaxY(self.headView.frame)+TabBarHeight)) collectionViewLayout:self.layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = UIColorFromRGB(0xEFEFEF);
        [_collectionView registerClass:[VideoHomeCell class] forCellWithReuseIdentifier:@"VideoHomeCell"];
    }
    return _collectionView;
}

- (UICollectionViewFlowLayout *)layout {
    if (!_layout) {
        _layout = [[UICollectionViewFlowLayout alloc]init];
        _layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _layout.itemSize = CGSizeMake((kScreenWidth - 2)/2.0, 120);
        _layout.minimumLineSpacing = 2;
        _layout.minimumInteritemSpacing = 2;
        
    }
    return _layout;
}

- (IBAction)rechargeBtcAction:(UIButton *)sender {
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
